package com.hgy.service.impl;

import com.hgy.dao.UserDao;
import com.hgy.entity.User;
import com.hgy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User login(String tel, String password) {
        User user = userDao.findByTel(tel);
        System.out.println(user);
        if (user == null) {
            throw new RuntimeException("账号错误");
        }
        if (!user.getPassword().equals(password)) {
            throw new RuntimeException("密码错误");
        }
        return user;
    }

    @Override
    public void addUser(User user) {
        userDao.addUser(user);
    }

    @Override
    public void updateUser(Integer id,String tel) {
        User user = new User();
        user.setId(id);
        user.setTel(tel);
        userDao.updateUser(user);
    }

}
